#include "CallButton.h"


CallButton::CallButton(void) {
	
}


CallButton::~CallButton(void){

}
void CallButton::init(void) {
	elevatorID = -1;
	callState = WAIT_PASSENGER;
}

void CallButton::elevatorLeaving(int elevID, bool QEmpty){
	if(elevID == elevatorID) {
	// Walker: Proposed change
	//if ( (callState == LOAD_PASSENGERS)&&(elevID == elevatorID) ) {
		if(!QEmpty) {
			callState = WAIT_FOR_RESPONSE;
		}
		else {
			callState = WAIT_PASSENGER;
		}
	// Walker: Proposed change
	// Reset elevator ID to invalid number
		elevatorID = -1;
	}
}

//BUG Walker: the code here belongs in is button pushed.
void CallButton::callElevator(void) {
	if(callState == WAIT_PASSENGER) {
		callState = WAIT_FOR_RESPONSE;
	// Walker: proposed fix
	//if (callState == WAIT_PASSENGER) {
	//  callState = WAIT_FOR_RESPONSE);
	}
}

void CallButton::elevatorLoading(int elevID) {
	if(callState == WAIT_FOR_ARRIVAL) {
		if(elevID == elevatorID) {
			callState = LOAD_PASSENGERS;
		}
	}
}

//BUG Walker: the callStates need to be changed. This is mostly callElevator code
bool CallButton::isButtonPushed(int elevID) {
	if(callState == WAIT_FOR_RESPONSE) {
		callState = WAIT_FOR_ARRIVAL;
	// Walker: proposed fix
	//if(callState == WAIT_FOR_RESPONSE) {
	//	callState = WAIT_FOR_ARRIVAL;
		elevatorID = elevID;
		return true;
	}
	return false;
}
